package br.uneb.tebd.util;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.test.ActivityInstrumentationTestCase2;
import br.uneb.tebd.MainActivity;

public class DatabaseUnitTest extends ActivityInstrumentationTestCase2<MainActivity> {
	
	private MainActivity mainActivity;
	private SQLiteDatabase database;
	
	public DatabaseUnitTest() {
		super("br.uneb.tebd.MainActivity", MainActivity.class);
	}
	
	
	
	@Override
	protected void setUp() throws Exception {
		
		super.setUp();
		
		this.mainActivity = getActivity(); 
		
	}



	public void testRegisterGuitar() {
		
		//Captura da instância do banco de dados através da classe Singleton
		database = DatabaseInstance.GET.getDatabaseInstance(this.mainActivity);

		ContentValues values = new ContentValues();
		
		values.put("description", "Condor 65DX");
		values.put("model", "Strato");
		values.put("brand", "Condor");
		
		long keyOfObject = database.insert("Guitars", null, values);
		
		assertNotSame(-1, keyOfObject);
		
	}
	
	public void testEditGuitar() {
		
		long id = 4;
		
		database = DatabaseInstance.GET.getDatabaseInstance(this.mainActivity);
		
		String guitarId = Long.toString(id);
		
		ContentValues values = new ContentValues();
		
		values.put("description", "Condor Nova Descri");
		values.put("model", "Lespaul");
		values.put("brand", "Condor 2.0");
		
		assertEquals(1, database.update("Guitars", values, "id = " + guitarId, null));
		//database.update("Guitars", values, "id = ?", new String[]{ guitarId });
		
	}
	
	public void testDeleteGuitar() {
		
		long id = 8;
		
		database = DatabaseInstance.GET.getDatabaseInstance(this.mainActivity);
		
		String guitarId = Long.toString(id);
		
		assertEquals(1, database.delete("Guitars", "id = ?", new String[] { guitarId }));
		
	}
	
	
}
